
public class LinkedList<DATA>
{
	class LinkedListNode
	{
		DATA data;
		LinkedListNode next;
		
		/**
		 * head->[0]->[1]->[2]->[3]->null
		 * @return
		 */
		LinkedListNode last()
		{
			LinkedListNode iter = this;
			while(iter != null && iter.next != null)
			{
				iter = iter.next;
			}
			return iter;
		}
		LinkedListNode(DATA d)
		{
			data = d;
		}
	}
	LinkedListNode head;
	
	void add(DATA d)
	{
		LinkedListNode newNode = new LinkedListNode(d);
		add(newNode);
	}
	
	void add(LinkedListNode newNode)
	{
		if(head == null)
		{
			head = newNode;
		}else{
			head.last().next = newNode;
		}
	}
	
	LinkedListNode removeFirst()
	{
		LinkedListNode n = head;
		if(head != null)
		{
			head = head.next;
			n.next = null;
		}
		return n;
	}
	
	String print()
	{
		StringBuffer str = new StringBuffer();
		LinkedListNode iter = head;
		while(iter != null)
		{
			if(iter != head)
				str.append(", ");
			str.append(iter.data.toString());
			iter = iter.next;
		}
		return str.toString();
	}
}